<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >

    <ui:composition template="layout.xhtml">
        <ui:define name="corpo">
            <h:form id="criarSecao" acceptcharset="utf-8"> 
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexProtocolo.xhtml')}" value="Protocolo" update="@form" immediate="true"/> >
                    <p:commandLink  value="Tramitar" update="@form" immediate="true"/>
                </div>
                <p:panel header="Tramitar Protocolo">
                    <p:messages id="msg" autoUpdate="true"/>
                    <h:panelGrid columns="2" border="0" styleClass="textAlignRight" columnClasses="textAlignRight"> 
                        <h:outputLabel value="Código do Protocolo: "/>
                        <p:inputText value="#{managerTramite.cod}"
                                     id="protocoloInput"
                                     onblur="searchProtocolo()"
                                     required="true" size="41"  converterMessage="Código inválido"
                                     requiredMessage="O campo Protocolo é obrigatório ">
                            <f:convertNumber type="number" />
                        </p:inputText>
                    </h:panelGrid>

                    <p:remoteCommand name="searchProtocolo" 
                                     update="protocoloInput, infoProtocolo, cod, servProt, infoServProtocolo" 
                                     process="protocoloInput, infoProtocolo"
                                     actionListener="#{managerTramite.protocoloFind()}" /> 
                    <fieldset class="ui-fieldset">
                        <legend>Protocolo</legend> 

                        <h:panelGrid columns="4" 
                                     id="infoProtocolo"
                                     styleClass="textAlignRight" 
                                     columnClasses="textAlignRight"> 

                            <h:outputLabel rendered="#{managerTramite.protocolo eq null ? true : false}" 
                                           value="* Informe o código do protocolo no campo acima "/>

                            <h:outputLabel rendered="#{managerTramite.protocolo eq null ? false : true}" value="Cód.: "/>
                            <h:outputText  rendered="#{managerTramite.protocolo eq null ? false : true}" id="cod" 
                                           value="#{managerTramite.protocolo.id} "/>

                            <h:outputLabel rendered="#{managerTramite.protocolo eq null ? false : true}" value="Data: "/>
                            <h:outputText rendered="#{managerTramite.protocolo eq null ? false : true}" 
                                          value="#{managerTramite.protocolo.dataCad}" 
                                          style="float: right;" >  
                                <f:convertDateTime pattern="dd/MM/yyyy"/>
                            </h:outputText>

                            <h:outputLabel rendered="#{managerTramite.protocolo eq null ? false : true}" value="Interessado:"/>
                            <h:outputText rendered="#{managerTramite.protocolo eq null ? false : true}" value="#{managerTramite.protocolo.cliente.nome} "/>

                            <h:outputLabel rendered="#{managerTramite.protocolo eq null ? false : true}" value="Doc.:"/>
                            <h:outputText  value="#{managerTramite.protocolo.cliente.cpf eq null ?
                                                    managerTramite.protocolo.cliente.cnpj : 
                                                    managerTramite.protocolo.cliente.cpf} "/>
                            
                        </h:panelGrid>
                         <h:panelGrid columns="4" 
                                      style="width: 100%"
                                     id="infoServProtocolo"
                                     styleClass="textAlignRight" 
                                     columnClasses="textAlignRight">
                                    <p:dataTable var="sp" id="servProt"
                                                 style="width: 100%"
                                                 rendered="#{managerTramite.protocolo eq null ? false : true}"
                                                 value="#{managerTramite.protocolo.servicoProtocolos}" 
                                                 >  

                                        <f:facet name="header">  
                                            Serviços
                                        </f:facet>  
                                        <p:column headerText="Descrição" >  
                                            <h:outputText value="#{sp.atoItem.descricao}" />  
                                        </p:column>
                                        <p:column headerText="Valor" style="width:15%">  
                                            <h:outputText value="#{sp.valor}" />  
                                        </p:column>

                                    </p:dataTable>
                         </h:panelGrid>
                        

                    </fieldset>
                    <fieldset class="ui-fieldset">
                        <legend>Unidade Remetente</legend> 
                        <h:panelGrid columns="2"  border="0" styleClass="textAlignRight" columnClasses="textAlignRight"> 
                            <h:outputLabel value="Nome: "/>
                            <p:inputText value="#{managerTramite.usuario.nome}"
                                         disabled="true"
                                         required="true" size="50" 
                                         requiredMessage="O campo nome deve ser preenchido "/>

                            <h:outputLabel value="Seção: "/>
                            <p:autoComplete id="secaoUsuario" effect="blind"
                                            value="#{managerTramite.tramite.remetente}" 
                                            scrollHeight="200" completeMethod="#{managerTramite.secaoUsuarioContexto}"  
                                            size="100" var="s" itemLabel="#{s.nome}" 
                                            forceSelection="true" itemValue="#{s}" converter="secaoConverter"  
                                            converterMessage="Erro, verifique o campo seção" minQueryLength="3" 
                                            dropdown="true" required="true" requiredMessage="O campo 'Seção' é obrigatório"> 

                            </p:autoComplete>

                        </h:panelGrid>
                    </fieldset>
                    <fieldset class="ui-fieldset">
                        <legend>Unidade de Destino</legend> 
                        <h:panelGrid columns="2"  border="0"
                                     id="panelDestino" styleClass="textAlignRight" columnClasses="textAlignRight"> 
                            <h:outputLabel value="Seção: "/>
                            <p:autoComplete id="secaoDestino" effect="blind"
                                            value="#{managerTramite.tramite.destino}" 
                                            scrollHeight="200" completeMethod="#{managerSecao.completeSecao}"  
                                            size="100" var="s" itemLabel="#{s.nome}" 
                                            forceSelection="true" itemValue="#{s}" converter="secaoConverter"  
                                            converterMessage="Erro, verifique o campo seção" minQueryLength="3" 
                                            dropdown="true" required="true" requiredMessage="O campo 'Seção' é obrigatório"> 
                                <p:ajax event="itemSelect" listener="#{managerTramite.usuarioDestinatario}"
                                        process="@this" update="usuarioDestino"/>
                            </p:autoComplete>

                            <h:outputLabel value="Usuário: "/>
                            <p:autoComplete id="usuarioDestino" effect="blind"
                                            disabled="#{managerTramite.tramite.destino eq null ? true : false}"
                                            value="#{managerTramite.tramite.usrDestino}" 
                                            scrollHeight="200" completeMethod="#{managerTramite.completeUsrDestino}"  
                                            size="100" var="s" itemLabel="#{s.nome}" 
                                            forceSelection="true" itemValue="#{s}" converter="usuarioConverter"  
                                            converterMessage="Erro, verifique o campo seção" minQueryLength="3" 
                                            dropdown="true" > 
                            </p:autoComplete>

                        </h:panelGrid>
                    </fieldset> 
                    <fieldset class="ui-fieldset">
                        <legend>Protocolo</legend> 
                        <h:panelGrid columns="4"  border="0"
                                     id="panelProtocolo" styleClass="textAlignRight" columnClasses="textAlignRight"> 
                            <h:outputLabel value="Situação: "/>
                            <p:autoComplete id="situacao" effect="blind"
                                            value="#{managerTramite.tramite.situacao}" 
                                            scrollHeight="200" completeMethod="#{managerSituacao.autoComplete}"  
                                            var="s" itemLabel="#{s.nome}" 
                                            forceSelection="true" itemValue="#{s}" converter="situacaoConverter"  
                                            converterMessage="Erro, verifique o campo situacao" minQueryLength="3" 
                                            dropdown="true" > 
                            </p:autoComplete>

                            <h:outputLabel value="Prazo conclusão: "/>
                            <p:calendar id="prazoConcl" value="#{managerTramite.tramite.prazoConclusao}"
                                        mode="popup" pattern="dd/MM/yyyy" showOn="button"
                                        locale="pt" showButtonPanel="true" navigator="true" 
                                        style="width: 30px" size="17"/>

                        </h:panelGrid>
                        <h:panelGrid columns="2"  border="0"
                                     styleClass="textAlignRight" columnClasses="textAlignRight"> 

                            <h:outputLabel value="Assunto: "/>
                            <p:inputText size="102" value="#{managerTramite.tramite.assunto}"/>
                            <h:outputLabel value="Despacho: "/>
                            <p:inputTextarea cols="102" value="#{managerTramite.tramite.despacho}"/>

                        </h:panelGrid>

                    </fieldset> 

                    <div class="buttonAction">
                        <p:commandButton id="id_submit"  icon="ui-icon-disk" 
                                         value="Salvar" actionListener="#{managerTramite.tramitar()}"
                                         update="@form" />
                        <p:commandButton value="Cancelar" icon="ui-icon-arrowreturnthick-1-w" 
                                         actionListener="#{managerCorSelo.redirect('indexCorSelo.xhtml')}" 
                                         immediate="true"/>
                    </div>

                </p:panel>   
                <p:ajaxStatus style="width:16px;height:16px;" id="ajaxStatusPanel">  
                    <f:facet name="start">  
                        <h:graphicImage value="/media/img/loading.gif" />  
                    </f:facet>  

                    <f:facet name="complete">  
                        <h:outputText value="" />  
                    </f:facet>  
                </p:ajaxStatus>
            </h:form>
        </ui:define>
    </ui:composition> 
</html>